import { QueryClient, useQuery } from "@tanstack/react-query";
import { LessonService } from "@/shared/api/api.lesson";

export function useGetAllLessons() {
    const queryClient = new QueryClient
    const { isLoading, error, data, refetch, isSuccess } =
        useQuery(
            {
                queryKey: ['lessons'],
                queryFn: LessonService.getAll,
                retry: 3
            }, queryClient
        )

    const errorMessage = error ? "Load lessons failed" : undefined;

    return {
        isLoading,
        lessons: data,
        errorMessage,
        refetch,
        isSuccess
    };
}